SET NOCOUNT ON
GO
USE [SMQuiz]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Insert]
	@AppID int output,
	@AppName nvarchar(100) = null ,
	@DisplayName nvarchar(100) = null ,
	@Description nvarchar(1000) = null ,
	@StartDate datetime = null 

AS

INSERT [dbo].[Apps]
(
	[AppName],
	[DisplayName],
	[Description],
	[StartDate]

)
VALUES
(
	@AppName,
	@DisplayName,
	@Description,
	@StartDate

)
	SELECT @AppID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Update]
	@AppID int,
	@AppName nvarchar(100) = null,
	@DisplayName nvarchar(100) = null,
	@Description nvarchar(1000) = null,
	@StartDate datetime = null

AS

UPDATE [dbo].[Apps]
SET
	[AppName] = @AppName,
	[DisplayName] = @DisplayName,
	[Description] = @Description,
	[StartDate] = @StartDate
 WHERE 
	[AppID] = @AppID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_SelectByPrimaryKey]
	@AppID int
AS

	SELECT 
		[AppID], [AppName], [DisplayName], [Description], [StartDate]
	FROM [dbo].[Apps]
	WHERE 
			[AppID] = @AppID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_SelectAll]
AS

	SELECT 
		[AppID], [AppName], [DisplayName], [Description], [StartDate]
	FROM [dbo].[Apps]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [AppID], [AppName], [DisplayName], [Description], [StartDate] FROM [dbo].[Apps] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [AppID], [AppName], [DisplayName], [Description], [StartDate] FROM [dbo].[Apps] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_DeleteByPrimaryKey]
	@AppID int
AS

DELETE FROM [dbo].[Apps]
 WHERE 
	[AppID] = @AppID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Apps] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Suppliers_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Suppliers_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Suppliers_Insert]
	@SupplierID int ,
	@SupplierName nvarchar(100) = null 

AS

INSERT [dbo].[Suppliers]
(
	[SupplierID],
	[SupplierName]

)
VALUES
(
	@SupplierID,
	@SupplierName

)


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Suppliers_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Suppliers_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Suppliers_Update]
	@SupplierID int,
	@SupplierName nvarchar(100) = null

AS

UPDATE [dbo].[Suppliers]
SET
	[SupplierID] = @SupplierID,
	[SupplierName] = @SupplierName
 WHERE 
	[SupplierID] = @SupplierID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Suppliers_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Suppliers_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Suppliers_SelectByPrimaryKey]
	@SupplierID int
AS

	SELECT 
		[SupplierID], [SupplierName]
	FROM [dbo].[Suppliers]
	WHERE 
			[SupplierID] = @SupplierID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Suppliers_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Suppliers_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Suppliers_SelectAll]
AS

	SELECT 
		[SupplierID], [SupplierName]
	FROM [dbo].[Suppliers]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Suppliers_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Suppliers_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Suppliers_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [SupplierID], [SupplierName] FROM [dbo].[Suppliers] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Suppliers_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Suppliers_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Suppliers_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Suppliers_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Suppliers_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Suppliers_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Suppliers_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Suppliers_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Suppliers_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [SupplierID], [SupplierName] FROM [dbo].[Suppliers] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Suppliers_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Suppliers_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Suppliers_DeleteByPrimaryKey]
	@SupplierID int
AS

DELETE FROM [dbo].[Suppliers]
 WHERE 
	[SupplierID] = @SupplierID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Suppliers_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Suppliers_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Suppliers_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Suppliers] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Platforms_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Platforms_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Platforms_Insert]
	@PlatformID int output,
	@PlatformName nvarchar(100) = null ,
	@SupplierID int = null 

AS

INSERT [dbo].[Platforms]
(
	[PlatformName],
	[SupplierID]

)
VALUES
(
	@PlatformName,
	@SupplierID

)
	SELECT @PlatformID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Platforms_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Platforms_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Platforms_Update]
	@PlatformID int,
	@PlatformName nvarchar(100) = null,
	@SupplierID int = null

AS

UPDATE [dbo].[Platforms]
SET
	[PlatformName] = @PlatformName,
	[SupplierID] = @SupplierID
 WHERE 
	[PlatformID] = @PlatformID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Platforms_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Platforms_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Platforms_SelectByPrimaryKey]
	@PlatformID int
AS

	SELECT 
		[PlatformID], [PlatformName], [SupplierID]
	FROM [dbo].[Platforms]
	WHERE 
			[PlatformID] = @PlatformID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Platforms_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Platforms_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Platforms_SelectAll]
AS

	SELECT 
		[PlatformID], [PlatformName], [SupplierID]
	FROM [dbo].[Platforms]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Platforms_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Platforms_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Platforms_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [PlatformID], [PlatformName], [SupplierID] FROM [dbo].[Platforms] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Platforms_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Platforms_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Platforms_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Platforms_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Platforms_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Platforms_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Platforms_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Platforms_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Platforms_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [PlatformID], [PlatformName], [SupplierID] FROM [dbo].[Platforms] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Platforms_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Platforms_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Platforms_DeleteByPrimaryKey]
	@PlatformID int
AS

DELETE FROM [dbo].[Platforms]
 WHERE 
	[PlatformID] = @PlatformID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Platforms_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Platforms_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Platforms_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Platforms] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Plats_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Plats_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Plats_Insert]
	@PlatformID int ,
	@AppID int 

AS

INSERT [dbo].[Apps_Plats]
(
	[PlatformID],
	[AppID]

)
VALUES
(
	@PlatformID,
	@AppID

)


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Plats_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Plats_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Plats_Update]
	@PlatformID int,
	@AppID int

AS

UPDATE [dbo].[Apps_Plats]
SET
	[PlatformID] = @PlatformID,
	[AppID] = @AppID
 WHERE 
	[PlatformID] = @PlatformID AND 
	[AppID] = @AppID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Plats_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Plats_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Plats_SelectByPrimaryKey]
	@PlatformID int,
	@AppID int
AS

	SELECT 
		[PlatformID], [AppID]
	FROM [dbo].[Apps_Plats]
	WHERE 
			[PlatformID] = @PlatformID AND 
	[AppID] = @AppID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Plats_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Plats_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Plats_SelectAll]
AS

	SELECT 
		[PlatformID], [AppID]
	FROM [dbo].[Apps_Plats]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Plats_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Plats_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Plats_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [PlatformID], [AppID] FROM [dbo].[Apps_Plats] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Plats_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Plats_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Plats_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Plats_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Plats_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Plats_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Plats_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Plats_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Plats_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [PlatformID], [AppID] FROM [dbo].[Apps_Plats] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Plats_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Plats_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Plats_DeleteByPrimaryKey]
	@PlatformID int,
	@AppID int
AS

DELETE FROM [dbo].[Apps_Plats]
 WHERE 
	[PlatformID] = @PlatformID AND 
	[AppID] = @AppID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Plats_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Plats_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Plats_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Apps_Plats] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Languages_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Languages_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Languages_Insert]
	@LanguageID int output,
	@LanguageName nvarchar(100) = null ,
	@Link nvarchar(100) = null 

AS

INSERT [dbo].[Languages]
(
	[LanguageName],
	[Link]

)
VALUES
(
	@LanguageName,
	@Link

)
	SELECT @LanguageID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Languages_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Languages_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Languages_Update]
	@LanguageID int,
	@LanguageName nvarchar(100) = null,
	@Link nvarchar(100) = null

AS

UPDATE [dbo].[Languages]
SET
	[LanguageName] = @LanguageName,
	[Link] = @Link
 WHERE 
	[LanguageID] = @LanguageID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Languages_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Languages_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Languages_SelectByPrimaryKey]
	@LanguageID int
AS

	SELECT 
		[LanguageID], [LanguageName], [Link]
	FROM [dbo].[Languages]
	WHERE 
			[LanguageID] = @LanguageID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Languages_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Languages_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Languages_SelectAll]
AS

	SELECT 
		[LanguageID], [LanguageName], [Link]
	FROM [dbo].[Languages]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Languages_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Languages_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Languages_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [LanguageID], [LanguageName], [Link] FROM [dbo].[Languages] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Languages_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Languages_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Languages_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Languages_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Languages_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Languages_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Languages_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Languages_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Languages_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [LanguageID], [LanguageName], [Link] FROM [dbo].[Languages] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Languages_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Languages_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Languages_DeleteByPrimaryKey]
	@LanguageID int
AS

DELETE FROM [dbo].[Languages]
 WHERE 
	[LanguageID] = @LanguageID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Languages_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Languages_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Languages_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Languages] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Categories_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Categories_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Categories_Insert]
	@CategoryID int output,
	@CategoryName nvarchar(100) = null ,
	@Tags nvarchar(500) = null ,
	@Description nvarchar(1000) = null ,
	@LanguageID int = null ,
	@UserID int = null 

AS

INSERT [dbo].[Categories]
(
	[CategoryName],
	[Tags],
	[Description],
	[LanguageID],
	[UserID]

)
VALUES
(
	@CategoryName,
	@Tags,
	@Description,
	@LanguageID,
	@UserID

)
	SELECT @CategoryID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Categories_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Categories_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Categories_Update]
	@CategoryID int,
	@CategoryName nvarchar(100) = null,
	@Tags nvarchar(500) = null,
	@Description nvarchar(1000) = null,
	@LanguageID int = null,
	@UserID int = null

AS

UPDATE [dbo].[Categories]
SET
	[CategoryName] = @CategoryName,
	[Tags] = @Tags,
	[Description] = @Description,
	[LanguageID] = @LanguageID,
	[UserID] = @UserID
 WHERE 
	[CategoryID] = @CategoryID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Categories_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Categories_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Categories_SelectByPrimaryKey]
	@CategoryID int
AS

	SELECT 
		[CategoryID], [CategoryName], [Tags], [Description], [LanguageID], [UserID]
	FROM [dbo].[Categories]
	WHERE 
			[CategoryID] = @CategoryID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Categories_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Categories_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Categories_SelectAll]
AS

	SELECT 
		[CategoryID], [CategoryName], [Tags], [Description], [LanguageID], [UserID]
	FROM [dbo].[Categories]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Categories_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Categories_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Categories_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [CategoryID], [CategoryName], [Tags], [Description], [LanguageID], [UserID] FROM [dbo].[Categories] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Categories_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Categories_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Categories_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Categories_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Categories_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Categories_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Categories_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Categories_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Categories_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [CategoryID], [CategoryName], [Tags], [Description], [LanguageID], [UserID] FROM [dbo].[Categories] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Categories_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Categories_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Categories_DeleteByPrimaryKey]
	@CategoryID int
AS

DELETE FROM [dbo].[Categories]
 WHERE 
	[CategoryID] = @CategoryID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Categories_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Categories_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Categories_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Categories] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Quizzes_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Quizzes_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Quizzes_Insert]
	@QuizID int output,
	@QuizName nvarchar(100) = null ,
	@Tags nvarchar(500) = null ,
	@Description nvarchar(1000) = null ,
	@UserID int = null ,
	@CategoryID int = null ,
	@Media nvarchar(1000) = null ,
	@Attemps int = null ,
	@Createdate datetime = null ,
	@isPrivate int = null ,
	@DownloadCount int = null 

AS

INSERT [dbo].[Quizzes]
(
	[QuizName],
	[Tags],
	[Description],
	[UserID],
	[CategoryID],
	[Media],
	[Attemps],
	[Createdate],
	[isPrivate],
	[DownloadCount]

)
VALUES
(
	@QuizName,
	@Tags,
	@Description,
	@UserID,
	@CategoryID,
	@Media,
	@Attemps,
	@Createdate,
	@isPrivate,
	@DownloadCount

)
	SELECT @QuizID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Quizzes_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Quizzes_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Quizzes_Update]
	@QuizID int,
	@QuizName nvarchar(100) = null,
	@Tags nvarchar(500) = null,
	@Description nvarchar(1000) = null,
	@UserID int = null,
	@CategoryID int = null,
	@Media nvarchar(1000) = null,
	@Attemps int = null,
	@Createdate datetime = null,
	@isPrivate int = null,
	@DownloadCount int = null

AS

UPDATE [dbo].[Quizzes]
SET
	[QuizName] = @QuizName,
	[Tags] = @Tags,
	[Description] = @Description,
	[UserID] = @UserID,
	[CategoryID] = @CategoryID,
	[Media] = @Media,
	[Attemps] = @Attemps,
	[Createdate] = @Createdate,
	[isPrivate] = @isPrivate,
	[DownloadCount] = @DownloadCount
 WHERE 
	[QuizID] = @QuizID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Quizzes_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Quizzes_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Quizzes_SelectByPrimaryKey]
	@QuizID int
AS

	SELECT 
		[QuizID], [QuizName], [Tags], [Description], [UserID], [CategoryID], [Media], [Attemps], [Createdate], [isPrivate], [DownloadCount]
	FROM [dbo].[Quizzes]
	WHERE 
			[QuizID] = @QuizID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Quizzes_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Quizzes_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Quizzes_SelectAll]
AS

	SELECT 
		[QuizID], [QuizName], [Tags], [Description], [UserID], [CategoryID], [Media], [Attemps], [Createdate], [isPrivate], [DownloadCount]
	FROM [dbo].[Quizzes]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Quizzes_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Quizzes_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Quizzes_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [QuizID], [QuizName], [Tags], [Description], [UserID], [CategoryID], [Media], [Attemps], [Createdate], [isPrivate], [DownloadCount] FROM [dbo].[Quizzes] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Quizzes_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Quizzes_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Quizzes_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Quizzes_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Quizzes_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Quizzes_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Quizzes_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Quizzes_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Quizzes_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [QuizID], [QuizName], [Tags], [Description], [UserID], [CategoryID], [Media], [Attemps], [Createdate], [isPrivate], [DownloadCount] FROM [dbo].[Quizzes] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Quizzes_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Quizzes_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Quizzes_DeleteByPrimaryKey]
	@QuizID int
AS

DELETE FROM [dbo].[Quizzes]
 WHERE 
	[QuizID] = @QuizID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Quizzes_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Quizzes_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Quizzes_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Quizzes] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Likes_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Likes_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Likes_Insert]
	@QuizID int ,
	@UserID int ,
	@CreateDate datetime = null 

AS

INSERT [dbo].[Likes]
(
	[QuizID],
	[UserID],
	[CreateDate]

)
VALUES
(
	@QuizID,
	@UserID,
	@CreateDate

)


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Likes_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Likes_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Likes_Update]
	@QuizID int,
	@UserID int,
	@CreateDate datetime = null

AS

UPDATE [dbo].[Likes]
SET
	[QuizID] = @QuizID,
	[UserID] = @UserID,
	[CreateDate] = @CreateDate
 WHERE 
	[QuizID] = @QuizID AND 
	[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Likes_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Likes_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Likes_SelectByPrimaryKey]
	@QuizID int,
	@UserID int
AS

	SELECT 
		[QuizID], [UserID], [CreateDate]
	FROM [dbo].[Likes]
	WHERE 
			[QuizID] = @QuizID AND 
	[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Likes_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Likes_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Likes_SelectAll]
AS

	SELECT 
		[QuizID], [UserID], [CreateDate]
	FROM [dbo].[Likes]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Likes_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Likes_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Likes_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [QuizID], [UserID], [CreateDate] FROM [dbo].[Likes] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Likes_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Likes_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Likes_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Likes_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Likes_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Likes_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Likes_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Likes_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Likes_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [QuizID], [UserID], [CreateDate] FROM [dbo].[Likes] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Likes_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Likes_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Likes_DeleteByPrimaryKey]
	@QuizID int,
	@UserID int
AS

DELETE FROM [dbo].[Likes]
 WHERE 
	[QuizID] = @QuizID AND 
	[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Likes_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Likes_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Likes_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Likes] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Reviews_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Reviews_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Reviews_Insert]
	@QuizID int ,
	@UserID int ,
	@CreateDate datetime = null ,
	@Rate int = null 

AS

INSERT [dbo].[Reviews]
(
	[QuizID],
	[UserID],
	[CreateDate],
	[Rate]

)
VALUES
(
	@QuizID,
	@UserID,
	@CreateDate,
	@Rate

)


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Reviews_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Reviews_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Reviews_Update]
	@QuizID int,
	@UserID int,
	@CreateDate datetime = null,
	@Rate int = null

AS

UPDATE [dbo].[Reviews]
SET
	[QuizID] = @QuizID,
	[UserID] = @UserID,
	[CreateDate] = @CreateDate,
	[Rate] = @Rate
 WHERE 
	[QuizID] = @QuizID AND 
	[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Reviews_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Reviews_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Reviews_SelectByPrimaryKey]
	@QuizID int,
	@UserID int
AS

	SELECT 
		[QuizID], [UserID], [CreateDate], [Rate]
	FROM [dbo].[Reviews]
	WHERE 
			[QuizID] = @QuizID AND 
	[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Reviews_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Reviews_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Reviews_SelectAll]
AS

	SELECT 
		[QuizID], [UserID], [CreateDate], [Rate]
	FROM [dbo].[Reviews]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Reviews_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Reviews_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Reviews_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [QuizID], [UserID], [CreateDate], [Rate] FROM [dbo].[Reviews] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Reviews_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Reviews_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Reviews_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Reviews_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Reviews_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Reviews_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Reviews_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Reviews_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Reviews_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [QuizID], [UserID], [CreateDate], [Rate] FROM [dbo].[Reviews] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Reviews_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Reviews_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Reviews_DeleteByPrimaryKey]
	@QuizID int,
	@UserID int
AS

DELETE FROM [dbo].[Reviews]
 WHERE 
	[QuizID] = @QuizID AND 
	[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Reviews_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Reviews_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Reviews_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Reviews] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quizzes_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quizzes_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quizzes_Insert]
	@App_Quize_ID int output,
	@AppID int = null ,
	@QuizID int = null ,
	@Likes int = null 

AS

INSERT [dbo].[Apps_Quizzes]
(
	[AppID],
	[QuizID],
	[Likes]

)
VALUES
(
	@AppID,
	@QuizID,
	@Likes

)
	SELECT @App_Quize_ID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quizzes_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quizzes_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quizzes_Update]
	@App_Quize_ID int,
	@AppID int = null,
	@QuizID int = null,
	@Likes int = null

AS

UPDATE [dbo].[Apps_Quizzes]
SET
	[AppID] = @AppID,
	[QuizID] = @QuizID,
	[Likes] = @Likes
 WHERE 
	[App_Quize_ID] = @App_Quize_ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quizzes_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quizzes_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quizzes_SelectByPrimaryKey]
	@App_Quize_ID int
AS

	SELECT 
		[App_Quize_ID], [AppID], [QuizID], [Likes]
	FROM [dbo].[Apps_Quizzes]
	WHERE 
			[App_Quize_ID] = @App_Quize_ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quizzes_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quizzes_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quizzes_SelectAll]
AS

	SELECT 
		[App_Quize_ID], [AppID], [QuizID], [Likes]
	FROM [dbo].[Apps_Quizzes]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quizzes_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quizzes_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quizzes_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [App_Quize_ID], [AppID], [QuizID], [Likes] FROM [dbo].[Apps_Quizzes] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quizzes_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quizzes_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quizzes_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quizzes_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quizzes_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quizzes_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quizzes_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quizzes_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quizzes_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [App_Quize_ID], [AppID], [QuizID], [Likes] FROM [dbo].[Apps_Quizzes] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quizzes_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quizzes_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quizzes_DeleteByPrimaryKey]
	@App_Quize_ID int
AS

DELETE FROM [dbo].[Apps_Quizzes]
 WHERE 
	[App_Quize_ID] = @App_Quize_ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quizzes_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quizzes_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quizzes_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Apps_Quizzes] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Questions_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Questions_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Questions_Insert]
	@QuestionID int output,
	@QuestionName nvarchar(1000) = null ,
	@Description nvarchar(1000) = null ,
	@Tags nvarchar(500) = null ,
	@Media nvarchar(1000) = null ,
	@Likes int = null ,
	@Wiki nvarchar(500) = null ,
	@UserID int = null ,
	@QuizID int = null 

AS

INSERT [dbo].[Questions]
(
	[QuestionName],
	[Description],
	[Tags],
	[Media],
	[Likes],
	[Wiki],
	[UserID],
	[QuizID]

)
VALUES
(
	@QuestionName,
	@Description,
	@Tags,
	@Media,
	@Likes,
	@Wiki,
	@UserID,
	@QuizID

)
	SELECT @QuestionID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Questions_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Questions_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Questions_Update]
	@QuestionID int,
	@QuestionName nvarchar(1000) = null,
	@Description nvarchar(1000) = null,
	@Tags nvarchar(500) = null,
	@Media nvarchar(1000) = null,
	@Likes int = null,
	@Wiki nvarchar(500) = null,
	@UserID int = null,
	@QuizID int = null

AS

UPDATE [dbo].[Questions]
SET
	[QuestionName] = @QuestionName,
	[Description] = @Description,
	[Tags] = @Tags,
	[Media] = @Media,
	[Likes] = @Likes,
	[Wiki] = @Wiki,
	[UserID] = @UserID,
	[QuizID] = @QuizID
 WHERE 
	[QuestionID] = @QuestionID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Questions_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Questions_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Questions_SelectByPrimaryKey]
	@QuestionID int
AS

	SELECT 
		[QuestionID], [QuestionName], [Description], [Tags], [Media], [Likes], [Wiki], [UserID], [QuizID]
	FROM [dbo].[Questions]
	WHERE 
			[QuestionID] = @QuestionID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Questions_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Questions_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Questions_SelectAll]
AS

	SELECT 
		[QuestionID], [QuestionName], [Description], [Tags], [Media], [Likes], [Wiki], [UserID], [QuizID]
	FROM [dbo].[Questions]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Questions_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Questions_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Questions_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [QuestionID], [QuestionName], [Description], [Tags], [Media], [Likes], [Wiki], [UserID], [QuizID] FROM [dbo].[Questions] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Questions_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Questions_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Questions_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Questions_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Questions_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Questions_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Questions_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Questions_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Questions_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [QuestionID], [QuestionName], [Description], [Tags], [Media], [Likes], [Wiki], [UserID], [QuizID] FROM [dbo].[Questions] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Questions_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Questions_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Questions_DeleteByPrimaryKey]
	@QuestionID int
AS

DELETE FROM [dbo].[Questions]
 WHERE 
	[QuestionID] = @QuestionID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Questions_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Questions_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Questions_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Questions] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Choices_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Choices_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Choices_Insert]
	@ChoiceID int output,
	@ChoiceName nvarchar(1000) = null ,
	@Description nvarchar(1000) = null ,
	@IsCorrect int = null ,
	@Media nvarchar(1000) = null ,
	@QuestionID int = null 

AS

INSERT [dbo].[Choices]
(
	[ChoiceName],
	[Description],
	[IsCorrect],
	[Media],
	[QuestionID]

)
VALUES
(
	@ChoiceName,
	@Description,
	@IsCorrect,
	@Media,
	@QuestionID

)
	SELECT @ChoiceID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Choices_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Choices_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Choices_Update]
	@ChoiceID int,
	@ChoiceName nvarchar(1000) = null,
	@Description nvarchar(1000) = null,
	@IsCorrect int = null,
	@Media nvarchar(1000) = null,
	@QuestionID int = null

AS

UPDATE [dbo].[Choices]
SET
	[ChoiceName] = @ChoiceName,
	[Description] = @Description,
	[IsCorrect] = @IsCorrect,
	[Media] = @Media,
	[QuestionID] = @QuestionID
 WHERE 
	[ChoiceID] = @ChoiceID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Choices_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Choices_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Choices_SelectByPrimaryKey]
	@ChoiceID int
AS

	SELECT 
		[ChoiceID], [ChoiceName], [Description], [IsCorrect], [Media], [QuestionID]
	FROM [dbo].[Choices]
	WHERE 
			[ChoiceID] = @ChoiceID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Choices_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Choices_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Choices_SelectAll]
AS

	SELECT 
		[ChoiceID], [ChoiceName], [Description], [IsCorrect], [Media], [QuestionID]
	FROM [dbo].[Choices]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Choices_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Choices_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Choices_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [ChoiceID], [ChoiceName], [Description], [IsCorrect], [Media], [QuestionID] FROM [dbo].[Choices] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Choices_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Choices_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Choices_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Choices_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Choices_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Choices_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Choices_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Choices_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Choices_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [ChoiceID], [ChoiceName], [Description], [IsCorrect], [Media], [QuestionID] FROM [dbo].[Choices] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Choices_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Choices_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Choices_DeleteByPrimaryKey]
	@ChoiceID int
AS

DELETE FROM [dbo].[Choices]
 WHERE 
	[ChoiceID] = @ChoiceID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Choices_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Choices_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Choices_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Choices] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Wiki_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Wiki_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Wiki_Insert]
	@WikiID int output,
	@QuestionID int = null ,
	@ChoiceID int = null ,
	@Wiki nvarchar(1000) = null ,
	@Url nvarchar(500) = null 

AS

INSERT [dbo].[Wiki]
(
	[QuestionID],
	[ChoiceID],
	[Wiki],
	[Url]

)
VALUES
(
	@QuestionID,
	@ChoiceID,
	@Wiki,
	@Url

)
	SELECT @WikiID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Wiki_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Wiki_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Wiki_Update]
	@WikiID int,
	@QuestionID int = null,
	@ChoiceID int = null,
	@Wiki nvarchar(1000) = null,
	@Url nvarchar(500) = null

AS

UPDATE [dbo].[Wiki]
SET
	[QuestionID] = @QuestionID,
	[ChoiceID] = @ChoiceID,
	[Wiki] = @Wiki,
	[Url] = @Url
 WHERE 
	[WikiID] = @WikiID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Wiki_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Wiki_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Wiki_SelectByPrimaryKey]
	@WikiID int
AS

	SELECT 
		[WikiID], [QuestionID], [ChoiceID], [Wiki], [Url]
	FROM [dbo].[Wiki]
	WHERE 
			[WikiID] = @WikiID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Wiki_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Wiki_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Wiki_SelectAll]
AS

	SELECT 
		[WikiID], [QuestionID], [ChoiceID], [Wiki], [Url]
	FROM [dbo].[Wiki]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Wiki_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Wiki_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Wiki_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [WikiID], [QuestionID], [ChoiceID], [Wiki], [Url] FROM [dbo].[Wiki] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Wiki_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Wiki_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Wiki_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Wiki_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Wiki_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Wiki_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Wiki_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Wiki_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Wiki_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [WikiID], [QuestionID], [ChoiceID], [Wiki], [Url] FROM [dbo].[Wiki] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Wiki_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Wiki_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Wiki_DeleteByPrimaryKey]
	@WikiID int
AS

DELETE FROM [dbo].[Wiki]
 WHERE 
	[WikiID] = @WikiID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Wiki_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Wiki_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Wiki_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Wiki] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quests_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quests_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quests_Insert]
	@App_Quest_ID int output,
	@AppID int = null ,
	@QuestionID int = null 

AS

INSERT [dbo].[Apps_Quests]
(
	[AppID],
	[QuestionID]

)
VALUES
(
	@AppID,
	@QuestionID

)
	SELECT @App_Quest_ID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quests_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quests_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quests_Update]
	@App_Quest_ID int,
	@AppID int = null,
	@QuestionID int = null

AS

UPDATE [dbo].[Apps_Quests]
SET
	[AppID] = @AppID,
	[QuestionID] = @QuestionID
 WHERE 
	[App_Quest_ID] = @App_Quest_ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quests_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quests_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quests_SelectByPrimaryKey]
	@App_Quest_ID int
AS

	SELECT 
		[App_Quest_ID], [AppID], [QuestionID]
	FROM [dbo].[Apps_Quests]
	WHERE 
			[App_Quest_ID] = @App_Quest_ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quests_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quests_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quests_SelectAll]
AS

	SELECT 
		[App_Quest_ID], [AppID], [QuestionID]
	FROM [dbo].[Apps_Quests]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quests_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quests_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quests_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [App_Quest_ID], [AppID], [QuestionID] FROM [dbo].[Apps_Quests] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quests_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quests_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quests_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quests_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quests_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quests_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quests_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quests_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quests_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [App_Quest_ID], [AppID], [QuestionID] FROM [dbo].[Apps_Quests] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quests_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quests_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quests_DeleteByPrimaryKey]
	@App_Quest_ID int
AS

DELETE FROM [dbo].[Apps_Quests]
 WHERE 
	[App_Quest_ID] = @App_Quest_ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Apps_Quests_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Apps_Quests_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Apps_Quests_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Apps_Quests] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Insert]
	@TestID int output,
	@AppID int ,
	@UserID int ,
	@StartTime datetime = null ,
	@EndTime datetime = null ,
	@Score decimal = null 

AS

INSERT [dbo].[Test]
(
	[AppID],
	[UserID],
	[StartTime],
	[EndTime],
	[Score]

)
VALUES
(
	@AppID,
	@UserID,
	@StartTime,
	@EndTime,
	@Score

)
	SELECT @TestID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Update]
	@TestID int,
	@AppID int,
	@UserID int,
	@StartTime datetime = null,
	@EndTime datetime = null,
	@Score decimal = null

AS

UPDATE [dbo].[Test]
SET
	[AppID] = @AppID,
	[UserID] = @UserID,
	[StartTime] = @StartTime,
	[EndTime] = @EndTime,
	[Score] = @Score
 WHERE 
	[TestID] = @TestID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Test_SelectByPrimaryKey]
	@TestID int
AS

	SELECT 
		[TestID], [AppID], [UserID], [StartTime], [EndTime], [Score]
	FROM [dbo].[Test]
	WHERE 
			[TestID] = @TestID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Test_SelectAll]
AS

	SELECT 
		[TestID], [AppID], [UserID], [StartTime], [EndTime], [Score]
	FROM [dbo].[Test]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Test_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [TestID], [AppID], [UserID], [StartTime], [EndTime], [Score] FROM [dbo].[Test] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Test_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Test_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Test_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [TestID], [AppID], [UserID], [StartTime], [EndTime], [Score] FROM [dbo].[Test] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Test_DeleteByPrimaryKey]
	@TestID int
AS

DELETE FROM [dbo].[Test]
 WHERE 
	[TestID] = @TestID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Test_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Test] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Question_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Question_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Question_Insert]
	@Test_Question_ID int output,
	@TestID int ,
	@QuestionID int ,
	@ChoiceID int = null ,
	@IsCorrect int = null 

AS

INSERT [dbo].[Test_Question]
(
	[TestID],
	[QuestionID],
	[ChoiceID],
	[IsCorrect]

)
VALUES
(
	@TestID,
	@QuestionID,
	@ChoiceID,
	@IsCorrect

)
	SELECT @Test_Question_ID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Question_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Question_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Question_Update]
	@Test_Question_ID int,
	@TestID int,
	@QuestionID int,
	@ChoiceID int = null,
	@IsCorrect int = null

AS

UPDATE [dbo].[Test_Question]
SET
	[TestID] = @TestID,
	[QuestionID] = @QuestionID,
	[ChoiceID] = @ChoiceID,
	[IsCorrect] = @IsCorrect
 WHERE 
	[Test_Question_ID] = @Test_Question_ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Question_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Question_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Question_SelectByPrimaryKey]
	@Test_Question_ID int
AS

	SELECT 
		[Test_Question_ID], [TestID], [QuestionID], [ChoiceID], [IsCorrect]
	FROM [dbo].[Test_Question]
	WHERE 
			[Test_Question_ID] = @Test_Question_ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Question_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Question_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Question_SelectAll]
AS

	SELECT 
		[Test_Question_ID], [TestID], [QuestionID], [ChoiceID], [IsCorrect]
	FROM [dbo].[Test_Question]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Question_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Question_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Question_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [Test_Question_ID], [TestID], [QuestionID], [ChoiceID], [IsCorrect] FROM [dbo].[Test_Question] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Question_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Question_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Question_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Question_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Question_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Question_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Question_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Question_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Question_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [Test_Question_ID], [TestID], [QuestionID], [ChoiceID], [IsCorrect] FROM [dbo].[Test_Question] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Question_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Question_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Question_DeleteByPrimaryKey]
	@Test_Question_ID int
AS

DELETE FROM [dbo].[Test_Question]
 WHERE 
	[Test_Question_ID] = @Test_Question_ID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Test_Question_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Test_Question_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Test_Question_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Test_Question] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Config_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Config_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Config_Insert]
	@ConfigID int output,
	@ConfigName nvarchar(100) = null ,
	@AppID int ,
	@Description nvarchar(1000) = null ,
	@ConfigValue int = null 

AS

INSERT [dbo].[Config]
(
	[ConfigName],
	[AppID],
	[Description],
	[ConfigValue]

)
VALUES
(
	@ConfigName,
	@AppID,
	@Description,
	@ConfigValue

)
	SELECT @ConfigID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Config_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Config_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Config_Update]
	@ConfigID int,
	@ConfigName nvarchar(100) = null,
	@AppID int,
	@Description nvarchar(1000) = null,
	@ConfigValue int = null

AS

UPDATE [dbo].[Config]
SET
	[ConfigName] = @ConfigName,
	[AppID] = @AppID,
	[Description] = @Description,
	[ConfigValue] = @ConfigValue
 WHERE 
	[ConfigID] = @ConfigID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Config_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Config_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Config_SelectByPrimaryKey]
	@ConfigID int
AS

	SELECT 
		[ConfigID], [ConfigName], [AppID], [Description], [ConfigValue]
	FROM [dbo].[Config]
	WHERE 
			[ConfigID] = @ConfigID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Config_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Config_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Config_SelectAll]
AS

	SELECT 
		[ConfigID], [ConfigName], [AppID], [Description], [ConfigValue]
	FROM [dbo].[Config]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Config_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Config_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Config_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [ConfigID], [ConfigName], [AppID], [Description], [ConfigValue] FROM [dbo].[Config] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Config_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Config_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Config_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Config_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Config_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Config_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Config_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Config_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Config_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [ConfigID], [ConfigName], [AppID], [Description], [ConfigValue] FROM [dbo].[Config] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Config_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Config_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Config_DeleteByPrimaryKey]
	@ConfigID int
AS

DELETE FROM [dbo].[Config]
 WHERE 
	[ConfigID] = @ConfigID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Config_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Config_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Config_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Config] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Roles_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Roles_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Roles_Insert]
	@RoleID int output,
	@RoleName nvarchar(100) = null ,
	@Description nvarchar(1000) = null 

AS

INSERT [dbo].[Roles]
(
	[RoleName],
	[Description]

)
VALUES
(
	@RoleName,
	@Description

)
	SELECT @RoleID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Roles_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Roles_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Roles_Update]
	@RoleID int,
	@RoleName nvarchar(100) = null,
	@Description nvarchar(1000) = null

AS

UPDATE [dbo].[Roles]
SET
	[RoleName] = @RoleName,
	[Description] = @Description
 WHERE 
	[RoleID] = @RoleID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Roles_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Roles_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Roles_SelectByPrimaryKey]
	@RoleID int
AS

	SELECT 
		[RoleID], [RoleName], [Description]
	FROM [dbo].[Roles]
	WHERE 
			[RoleID] = @RoleID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Roles_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Roles_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Roles_SelectAll]
AS

	SELECT 
		[RoleID], [RoleName], [Description]
	FROM [dbo].[Roles]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Roles_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Roles_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Roles_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [RoleID], [RoleName], [Description] FROM [dbo].[Roles] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Roles_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Roles_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Roles_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Roles_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Roles_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Roles_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Roles_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Roles_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Roles_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [RoleID], [RoleName], [Description] FROM [dbo].[Roles] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Roles_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Roles_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Roles_DeleteByPrimaryKey]
	@RoleID int
AS

DELETE FROM [dbo].[Roles]
 WHERE 
	[RoleID] = @RoleID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Roles_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Roles_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Roles_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Roles] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Users_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Users_Insert]
GO
CREATE PROCEDURE [dbo].[Sp_Users_Insert]
	@UserID int output,
	@UserName nvarchar(100) = null ,
	@DisplayName nvarchar(100) = null ,
	@Imei nvarchar(100) = null ,
	@Description nvarchar(1000) = null ,
	@Password nvarchar(100) = null ,
	@Email nvarchar(100) = null ,
	@RoleID int = null 

AS

INSERT [dbo].[Users]
(
	[UserName],
	[DisplayName],
	[Imei],
	[Description],
	[Password],
	[Email],
	[RoleID]

)
VALUES
(
	@UserName,
	@DisplayName,
	@Imei,
	@Description,
	@Password,
	@Email,
	@RoleID

)
	SELECT @UserID=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Users_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Users_Update]
GO
CREATE PROCEDURE [dbo].[Sp_Users_Update]
	@UserID int,
	@UserName nvarchar(100) = null,
	@DisplayName nvarchar(100) = null,
	@Imei nvarchar(100) = null,
	@Description nvarchar(1000) = null,
	@Password nvarchar(100) = null,
	@Email nvarchar(100) = null,
	@RoleID int = null

AS

UPDATE [dbo].[Users]
SET
	[UserName] = @UserName,
	[DisplayName] = @DisplayName,
	[Imei] = @Imei,
	[Description] = @Description,
	[Password] = @Password,
	[Email] = @Email,
	[RoleID] = @RoleID
 WHERE 
	[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Users_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Users_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Users_SelectByPrimaryKey]
	@UserID int
AS

	SELECT 
		[UserID], [UserName], [DisplayName], [Imei], [Description], [Password], [Email], [RoleID]
	FROM [dbo].[Users]
	WHERE 
			[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Users_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Users_SelectAll]
GO
CREATE PROCEDURE [dbo].[Sp_Users_SelectAll]
AS

	SELECT 
		[UserID], [UserName], [DisplayName], [Imei], [Description], [Password], [Email], [RoleID]
	FROM [dbo].[Users]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Users_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Users_SelectByField]
GO
CREATE PROCEDURE [dbo].[Sp_Users_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [UserID], [UserName], [DisplayName], [Imei], [Description], [Password], [Email], [RoleID] FROM [dbo].[Users] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Users_SelectBySql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Users_SelectBySql]
GO
CREATE PROCEDURE [dbo].[Sp_Users_SelectBySql]
	@Sql varchar(2000)
AS

	EXEC(@Sql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Users_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Users_RunSQL]
GO
CREATE PROCEDURE [dbo].[Sp_Users_RunSQL]
	@strSql varchar(3000)
AS

	EXEC(@strSql)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Users_SelectTableByWhereSql]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Users_SelectTableByWhereSql]
GO
CREATE PROCEDURE [dbo].[Sp_Users_SelectTableByWhereSql]
	@strWhere varchar(2000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [UserID], [UserName], [DisplayName], [Imei], [Description], [Password], [Email], [RoleID] FROM [dbo].[Users] WHERE '+@strWhere 
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Users_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Users_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[Sp_Users_DeleteByPrimaryKey]
	@UserID int
AS

DELETE FROM [dbo].[Users]
 WHERE 
	[UserID] = @UserID

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sp_Users_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[Sp_Users_DeleteByField]
GO
CREATE PROCEDURE [dbo].[Sp_Users_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Users] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO
